#include "WindowReader.h"

#include "Globals.h"

/*
 * C'tor:
 *	_window_size - the size the window will hold. -- this will be global
 *	_contents - the initial contents of the window.
 */
WindowReader::WindowReader(ulong _contents) :
		contents(_contents),
		mask((1UL << (windowSize << 1)) - 1)
{
}

WindowReader::~WindowReader()
{
}

/*
 * inserts the new_char to the right position (and shifts the left most char).
 */
WindowReader& WindowReader::push(ulong new_char)
{
	contents = ((contents << 2) | new_char) & mask;
	return *this;
}

#ifdef DEBUG

#include <iostream>
using namespace std;

void WindowReader::printStr() const
{
	char str[windowSize + 1];
	str[windowSize] = '\0';
	ulong cur_contents = contents;
	for (int i = windowSize-1; i >= 0; i--)
	{
		switch (cur_contents & 0x3UL)
		{
		case CHAR_A:
			str[i] = 'A';
			break;
		case CHAR_C:
			str[i] = 'C';
			break;
		case CHAR_G:
			str[i] = 'G';
			break;
		case CHAR_T:
			str[i] = 'T';
			break;
		default:
			// Should never reach here
			break;
		}
		cur_contents = cur_contents >> 2;
	}
	cout << contents << ", " << str;
}

#endif /* DEBUG */


